home *** CD-ROM | disk | FTP | other *** search
- Path: news.mcs.net!usenet
- From: Mike Young <mikey@mcs.com>
- Newsgroups: comp.lang.ada,comp.lang.c++
- Subject: Re: some questions re. Ada/GNAT from a C++/GCC user
- Date: Sun, 31 Mar 1996 21:16:45 -0600
- Organization: Fen Software, Inc.
- Message-ID: <315F4A9D.7E6F@mcs.com>
- References: <wnewmanDoxrCp.DKv@netcom.com> <SIMON.96Mar30153124@pogner.demon.co.uk> <315D902C.6F7B@escmail.orl.mmc.com> <Dp3G4u.KEA@world.std.com> <4jmuj5$lkh@dayuc.dayton.saic.com>
- NNTP-Posting-Host: mikey.pr.mcs.net
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0GoldB1 (Win95; I)
-
- John G. Volan wrote:
- >
- > One difficulty I see with intermingling declarations and statements is
- > how to interpret declarations within conditional or iterative constructs.
- > For instance:
- >
- > -- This is NOT Ada, this is CRAPOLA (C-Reminiscent Ada-like Perversion
- > -- Of Language Aspects) :-) :
- > begin
- > ...
- > if Smaller then
- > X : Integer;
- > ...
- > elsif Bigger then
- > X : Long_Integer;
- > ...
- > end if;
- > ...
- > -- is X in scope here, and if so, what the heck is it?
- > ...
-
- ==========
- (Cute acronym; not sure if I like it though. :)
-
- The scoping rules in C++ are quite simple: the object comes into
- existence at the point of definition, and persists until the end of the
- enclosing scope. In your example, X would is created at its declaration
- (eg.: X : Long_Integer;), and is destroyed at the corresponding elsif or
- endif.
-
- Sprinkling declarations willy-nilly throughout the code is more than a
- matter of convenience. Construction of objects sometimes entail
- non-trivial construction. Rather than force a two step process --
- construction at declaration, and then subsequent initialization -- it is
- very common to declare the object "just-in-time," and combine the two
- steps. This frees the object designer from allowing for an undefined
- state, which would exist if construction were separated from
- initialization.
-
- Personally, I like it this way. It's very easy to verify that all
- objects are correctly initialized before use when all objects are
- initialized at their points of construction. The object does not exist
- before it is initialized.
-
- Mike.
-